package com.dai.wechat.util;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;


public class Memorial {

    private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

    @Value("${teng.birthday}")
    private  String birthday;

    /**
     * 距离date还有多少天
     * @param date
     * @return
     */
    public static int before(String date) {
        int day = 0;
        try {
            long time = simpleDateFormat.parse(date).getTime() - System.currentTimeMillis();
            day = (int) (time / 86400000L);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return day;
    }


    /**
     * 已经过去date多少天
     * @param date
     * @return
     */
    public static int after(String date) {
        int day = 0;
        try {
            long time = System.currentTimeMillis() - simpleDateFormat.parse(date).getTime();
            day = (int) (time / 86400000L);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return day;
    }


    public static int getLoveDay(){

        return after("2021-12-27");

    }

    public static int getBirthDay(){

        return before("2023-01-25");

    }

    public static int getMeetDay(){

        return before("2022-08-25");

    }

    public static int getLeapYear(){
        SimpleDateFormat df = new SimpleDateFormat("yyyy");
        Integer year = Integer.valueOf(df.format(System.currentTimeMillis()));
        if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0 )
        {
            return 366;
        }
        else
        {
            return 365;
        }
    }

    public static String getToday(){
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String format = dateFormat.format(new Date());
        return format;
    }
}
